package org.catspaw.cherubim.matcher;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

/**
 * URL匹配器实现 用ant模式匹配url
 * @author 孙宁振
 */
public class AntUrlMatcher extends AbstractStringMatcher implements UrlMatcher {

	private PathMatcher	pathMatcher	= new AntPathMatcher(); //匹配器

	/**
	 * 判断指定资源描述符和指定url是否匹配
	 * @param pattern 资源描述符
	 * @param urlString url
	 * @return 是否匹配
	 */
	public boolean match(String pattern, String urlString) {
		String urlBody = UrlUtils.truncateParameters(urlString);
		if (isConvertUrlToLowercaseBeforeComparison()) {
			urlBody = getLowerCase(urlBody);
		}
		return getPathMatcher().match(pattern, urlBody);
	}

	public PathMatcher getPathMatcher() {
		return pathMatcher;
	}
}
